package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtEqp;
import com.ruoyi.prt.service.IPrtEqpService;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打印设备Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/eqp")
public class PrtEqpController extends BaseController
{
    @Autowired
    private IPrtEqpService prtEqpService;

    /**
     * 查询打印设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:eqp:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtEqp prtEqp)
    {
        startPage();
        List<PrtEqp> list = prtEqpService.selectPrtEqpList(prtEqp);
        return getDataTable(list);
    }

    /**
     * 导出打印设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:eqp:export')")
    @Log(title = "打印设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtEqp prtEqp)
    {
        List<PrtEqp> list = prtEqpService.selectPrtEqpList(prtEqp);
        ExcelUtil<PrtEqp> util = new ExcelUtil<PrtEqp>(PrtEqp.class);
        return util.exportExcel(list, "eqp");
    }

    /**
     * 获取打印设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:eqp:query')")
    @GetMapping(value = "/{eqpId}")
    public AjaxResult getInfo(@PathVariable("eqpId") String eqpId)
    {
        return AjaxResult.success(prtEqpService.selectPrtEqpById(eqpId));
    }

    /**
     * 新增打印设备
     */
    @PreAuthorize("@ss.hasPermi('system:eqp:add')")
    @Log(title = "打印设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtEqp prtEqp)
    {
        return toAjax(prtEqpService.insertPrtEqp(prtEqp));
    }

    /**
     * 修改打印设备
     */
    @PreAuthorize("@ss.hasPermi('system:eqp:edit')")
    @Log(title = "打印设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtEqp prtEqp)
    {
        return toAjax(prtEqpService.updatePrtEqp(prtEqp));
    }

    /**
     * 删除打印设备
     */
    @PreAuthorize("@ss.hasPermi('system:eqp:remove')")
    @Log(title = "打印设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eqpIds}")
    public AjaxResult remove(@PathVariable String[] eqpIds)
    {
        return toAjax(prtEqpService.deletePrtEqpByIds(eqpIds));
    }


    /**
     * 获取打印机状态
     */
    @ResponseBody
    @PreAuthorize("@ss.hasRole('mobile')")
    @GetMapping(value = "/getPrintState")
    public AjaxResult getPrintState(@Param("eqpName") String eqpName) {
        return AjaxResult.success(prtEqpService.selectPrtEqpByEqpName(eqpName));
    }
}
